package text_70;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;

public class Code {

	public static void main(String[] args) {
		 ArrayList<String> list = new ArrayList<>();
	        Collections.addAll(list,"张无忌-男-22","赵铭-女-18","张三峰-男-32","张三-男-43"
	                ,"张强-男-12","小龙女-女19","杨过-男-20");
	        //stream流,单列集合

	        List<String> newlist = list.stream()
	                //获取男性
	                .filter(s -> "男".equals(s.split("-")[1]))
	                //放入新集合
	                .collect(Collectors.toList());
	        System.out.println(newlist);
	        System.out.println("===========");

	        Set<String> collect = list.stream()
	                .filter(s -> "男".equals(s.split("-")[1]))
	                .collect(Collectors.toSet());
	        System.out.println(collect);
	        System.out.println("===========");
	        //双列集合
	        Map<String, String> collect1 = list.stream()
	                .filter(s -> "男".equals(s.split("-")[1]))
	                                            //键
	                .collect(Collectors.toMap(new Function<String, String>() {
	                    @Override
	                    public String apply(String s) {
	                        String[] split = s.split("-");
	                        String s1 = split[0];
	                        return s1;
	                    }//值
	                }, new Function<String, String>() {
	                    @Override
	                    public String apply(String s) {
	                        String[] split = s.split("-");
	                        String s1 = split[2];
	                        return s1;
	                    }
	                }));
	        System.out.println(collect1);
	        System.out.println("===========");
	        //化简
	        Map<String, Integer> collect2 = list.stream()
	                .filter(s -> "男".equals(s.split("-")[1]))
	                .collect(Collectors.toMap(
	                        s -> s.split("-")[0],
	                        s -> Integer.parseInt(s.split("-")[2])));
	        System.out.println(collect2);

	}

}
